package com.ruoyi.merchant.controller;

import com.ruoyi.merchant.utils.BaiduPlaceUtil;
import com.ruoyi.merchant.utils.SearchUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ysq
 * @Date: 2024/09/12/10:06
 * @Description:
 */
@RestController
@RequestMapping("/address")
public class MapController {

    @Autowired
    private BaiduPlaceUtil baiduPlaceUtil;

    @Autowired
    private SearchUtil searchUtil;

    /*
    * 搜索附近的加油站
    * */
    @GetMapping("/search")
    public String searchPlace(@RequestParam String query, @RequestParam String location, @RequestParam String radius) {
        Map<String, String> params = new HashMap<>();
        params.put("query", query);
        params.put("location", location);
        params.put("radius", "50000");
        params.put("output", "json");
        try {
            return baiduPlaceUtil.searchPlace(params);
        } catch (Exception e) {
            e.printStackTrace();
            return "Error occurred while fetching place data.";
        }
    }
    /*
    * 根据加油站获取详情
    * */
    @GetMapping("/details")
    public String getDetails(@RequestParam String uid, @RequestParam String scope) {
        Map<String, String> params = new HashMap<>();
        params.put("uid", uid);
        params.put("output", "json");
        params.put("scope", scope);

        try {
            return searchUtil.requestGetAK(params);
        } catch (Exception e) {
            e.printStackTrace();
            return "Error occurred while fetching details.";
        }
    }

}
